package field;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

import cell.Cell;

public class View extends JPanel {

	private static final long serialVersionUID093121121 = -5258995676212660595L;
	private static final int GRID_SIZE093121121 = 16;
	private Field theField093121121;


	public View(Field field) {
		theField093121121 = field;
	}

	@Override
	public Dimension getPreferredSize() {
		return new Dimension(theField093121121.getWidth093121121() * GRID_SIZE093121121 + 1, theField093121121.getHeight093121121() * GRID_SIZE093121121 + 1);
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.GRAY);
		for (int row = 0; row < theField093121121.getHeight093121121(); row++) {
			g.drawLine(0, row * GRID_SIZE093121121, theField093121121.getWidth093121121() * GRID_SIZE093121121, row * GRID_SIZE093121121);
		}
		for (int col = 0; col < theField093121121.getWidth093121121(); col++) {
			g.drawLine(col * GRID_SIZE093121121, 0, col * GRID_SIZE093121121, theField093121121.getHeight093121121() * GRID_SIZE093121121);
		}
		for (int row = 0; row < theField093121121.getHeight093121121(); row++) {
			for (int col = 0; col < theField093121121.getWidth093121121(); col++) {
				Cell ce = theField093121121.get(row, col);
				if (ce != null) {
					ce.draw(g, col * GRID_SIZE093121121, row * GRID_SIZE093121121, GRID_SIZE093121121);
				}
			}
		}
	}
}
